package com.moonlit.myspring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

/**
 * @Autowired 自动装配的注解
 * @Qualifier("falchion") 如果两个实现类同时实现了一个接口，那么可以使用@Qualifier("falchion")来选取你想要的实现
 */

//@Component("guanYu") 括号里的可以不写 默认会把类名转换成小写当作id

@Component
public class GuanYu implements Hero {
    @Autowired
    @Qualifier("falchion")
    private Weapon weapon;

    //用注解可以省略不写下面注释的代码
//    public void setWeapon(Weapon weapon) {
//        this.weapon = weapon;
//    }

    @Override
    public void perform() {
        System.out.println("GuanYu pick up his weapon");
        weapon.attack();
    }
}